<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-md-6">
        <h2>分类管理</h2>
        <ol class="breadcrumb">
            <li>
                <a href="index.html">主页</a>
            </li>
            <li class="active">
                <strong>分类管理</strong>
            </li>
        </ol>
    </div>
    <div class="col-md-6">
        <h2>
            <a class="btn btn-success btn-lg pull-right" href="{:U('admin/catalog/add')}">添加分类</a>
        </h2>
    </div>
</div>


<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>分类列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="fa fa-wrench"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                    <li><a href="#">Config option 1</a>
                    </li>
                    <li><a href="#">Config option 2</a>
                    </li>
                </ul>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <div class="ibox">
            <div class="ibox-content">
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>分类</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="level1" id="l1">
                        <tr class="level1" id="level{$l1.id}">
                            <td>{$l1.id}</td>
                            <td>{$l1.name}</td>
                            <td>
                                <a class="btn btn-primary btn-xs" href="{:U('admin/catalog/edit/id/'.$l1['id'])}">编辑</a>
                                <a class="btn btn-danger btn-xs delete" href="{:U('admin/catalog/delete/id/'.$l1['id'])}">删除</a>
                            </td>
                        </tr>
                        <?php $level2 = M('product_catalog')->where('parent_id = '.$l1['id'])->select();?>
                        <volist name="level2" id="l2">
                            <tr class="level2 parent_level{$l1.id}" id="level{$l2.id}">
                                <td>{$l2.id}</td>
                                <td>◢{$l2.name}</td>
                                <td>
                                    <a class="btn btn-primary btn-xs" href="{:U('admin/catalog/edit/id/'.$l2['id'])}">编辑</a>
                                    <a class="btn btn-danger btn-xs delete" href="{:U('admin/catalog/delete/id/'.$l2['id'])}">删除</a>
                                </td>
                            </tr>
                            <?php $level3 = M('product_catalog')->where('parent_id = '.$l2['id'])->select();?>
                            <volist name="level3" id="l3">
                                <tr class="level3 parent_level{$l2.id}">
                                    <td>{$l3.id}</td>
                                    <td>◢◢{$l3.name}</td>
                                    <td>
                                        <a class="btn btn-primary btn-xs" href="{:U('admin/catalog/edit/id/'.$l3['id'])}">编辑</a>
                                        <a class="btn btn-danger btn-xs delete" href="{:U('admin/catalog/delete/id/'.$l3['id'])}">删除</a>
                                    </td>
                                </tr>
                            </volist>
                        </volist>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<style type="text/css">
    .level1 td{
        cursor: pointer;
    }
    .level2 td{
        background: #eee;
        cursor: pointer;
    }
    .level3{
        background: #ccc;
        display: none;
    }
</style>
<script type="text/javascript">
    $(function(){
        $('.level2 td').click(function(){
            var id = $(this).parents('tr').attr('id');
            var c = '.parent_'+id;
            $(c).toggle(); 
        });
    })
</script>